package com.flight.trans.global;

import android.app.Application;
import android.content.Context;

import com.flight.trans.R;
import com.flight.trans.base.BaseActivity;
import com.flight.trans.listener.CrashHandler;
import com.flight.trans.receiver.BluetoothBootBroadcastReceiver;
import com.lzy.okgo.OkGo;

import java.util.ArrayList;

public class MainApplication extends Application {

    private static Context mContext ;

    private static ArrayList<BaseActivity> activityList ;
    private BluetoothBootBroadcastReceiver broadcastReceiver ;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this ;

        initUnusualList();

        broadcastReceiver = new BluetoothBootBroadcastReceiver();

        CrashHandler.getInstance().init();

        //初始化OkGo
        OkGo.getInstance().init(this);
    }

    /**
     * 初始化集合
     */
    private void initUnusualList() {
        ConstantInfo.UnusualGradleList = new ArrayList<>();
        ConstantInfo.UnusualGradleList.add("D1");
        ConstantInfo.UnusualGradleList.add("D2");
        ConstantInfo.UnusualGradleList.add("D3");

        ConstantInfo.ContainerList = new ArrayList<>();
        ConstantInfo.ContainerList.add(getString(R.string.text_tug));
        ConstantInfo.ContainerList.add(getString(R.string.text_container));
        ConstantInfo.ContainerList.add(getString(R.string.text_custom));
    }

    public static Context getContext(){
        return mContext ;
    }

    public static void addActivity(BaseActivity activity){
        if(activityList == null)
            activityList = new ArrayList<>();

        activityList.add(activity);
    }

    public static void finishActivity(){
        for (int i = 0; i < activityList.size() - 1; i++) {
            activityList.get(i).onFinish();
        }
    }

    public static void removeActivity(BaseActivity activity){
        activityList.remove(activity);
    }
}
